package com.shilei.noticemonitor;

import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import com.shilei.noticemonitor.conf.Settings;
import com.shilei.noticemonitor.util.SoundUtils;
import com.shilei.noticemonitor.util.VibratorUtil;

public class NotificationCollectorService extends NotificationListenerService {
    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        String packageName=sbn.getPackageName();
        CharSequence tickerText = sbn.getNotification().tickerText;
        String title ="";
        Object o = sbn.getNotification().extras.get("android.title");
        if(o!=null){
            title=o.toString();
        }
        String text ="";
        Object o1 = sbn.getNotification().extras.get("android.text");
        if(o1!=null){
            text=o1.toString();
        }
        Log.i("NotificationPosted", "应用包名" + "-----" + packageName);
        Log.i("NotificationPosted", "通知内容【通知栏专用】" + "------" + tickerText);
        Log.i("NotificationPosted", "通知标题" + "-----" + title);
        Log.i("NotificationPosted", "通知内容" + "-----" + text);

        if("com.tencent.mm".equals(packageName)){
            Log.i("NotificationPosted", "微信消息");
            if(tickerText.toString().contains("[**]:")){
                if (Settings.SOUND) SoundUtils.playSound(R.raw.b);
                if(Settings.VIBRATE) VibratorUtil.vibrate(500);
            }

        }

//            List<File> files = FileUtil.getAllFile("/storage/emulated/0/tencent/MicroMsg/WeiXin/", false);
//            List<File> files3 = FileUtil.getAllFile("/storage/emulated/0/Pictures/WeiXin/", false);
//        for (File file : files) {
//            Log.i("xiaolong files.for",file.getAbsolutePath());
//        }

    }

    @Override
    public void onNotificationRemoved(StatusBarNotification sbn) {
        Log.i("xiaolong", "remove" + "-----" + sbn.getPackageName());

    }

}
